#ifndef __RBL_ALGO_H_
#define __RBL_ALGO_H_

#include <stdio.h>
#include <string.h>
#include "stdint.h"
#include "fupdate.h"


int      rbl_crc32_init(void);
uint32_t rbl_crc32(uint8_t *buf, uint32_t len);
uint32_t rbl_step_crc32(uint32_t crc, uint8_t *buf, uint32_t len);

/**
 * fupdate AES256 encryption algorithm option
 */
#if (FUPDATE_USING_AES256 == 1)

void *rbl_aes256_decrypt_context_create(void);

void rbl_aes256_decrypt_context_delete(void *aes_ctx);

void rbl_aes256_decrypt_init_keyiv(void * rbl_aes_ctx,const uint8_t *aes_key, const uint8_t *aes_iv);

void rbl_aes256_decrypt_data(void * rbl_aes_ctx, uint8_t *src_buf, uint8_t *dst_buf,  uint32_t len);

#endif

/*
 * fupdate decompress mode
 */
#if (FUPDATE_USING_FASTLZ == 1)

void *rbl_fastlz_decompress_context_create(void);

void rbl_fastlz_decompress_context_delete(void *fastlz_decom_ctx);

uint32_t rbl_fastlz_decompress_get_block_size(void *fastlz_decom_ctx, const uint8_t *compress_datas);

uint32_t rbl_fastlz_decompress_data(void *fastlz_decom_ctx, uint8_t *out_buf, uint32_t out_buf_size, const uint8_t *in_buf, uint32_t block_size);


#define FUPDATE_FASTLZ_HEADER_SIZE 4

#ifndef FUPDATE_FASTLZ_BUFFER_PADDING_SIZE
#define FUPDATE_FASTLZ_BUFFER_PADDING_SIZE 2048
#endif

#endif

/*
 * fupdate decompress mode
 */
#if (FUPDATE_USING_QUICKLZ == 1)

void *rbl_quicklz_decompress_context_create(void);
void rbl_quicklz_decompress_context_delete(void *quicklz_decom_ctx);

uint32_t rbl_quicklz_decompress_get_block_size(void *quicklz_decom_ctx,const uint8_t *compress_datas);

uint32_t rbl_quicklz_decompress_data(void *quicklz_decom_ctx, uint8_t *out_buf, const uint8_t *in_buf);

#define FUPDATE_QUICKLZ_HEADER_SIZE 4

#ifndef FUPDATE_QUICKLZ_BUFFER_PADDING_SIZE
#define FUPDATE_QUICKLZ_BUFFER_PADDING_SIZE 2048
#endif

#endif
/*
 * fupdate decompress mode
 */
#if (FUPDATE_USING_GZIP == 1)

void *rbl_gzip_decompress_context_create(void);
void rbl_gzip_decompress_context_delete(void *gzip_decom_ctx);
void rbl_gzip_decompress_set_in(void *gzip_decom_ctx, uint8_t *in_buf, uint32_t in_size);
int rbl_gzip_decompress_data(void *gzip_decom_ctx, uint8_t *out_buf, uint32_t out_buf_size);

#define FUPDATE_GZIP_BUFFER_PADDING 2048

#endif


#endif /* _FOTA_H_ */
